Test Series - Data Structure

Test Number 55/115

Q: The number of edges from the root to the node is called __________ of the tree.
A. Height
B. Depth
C. Length
D. Width
Solution: The number of edges from the root to the node is called depth of the tree.
Q: The number of edges from the node to the deepest leaf is called _________ of the tree.
A. Height
B. Depth
C. Length
D. Width
Solution: The number of edges from the node to the deepest leaf is called height of the tree.
Q: What is a full binary tree?
A. Each node has exactly zero or two children
B. Each node has exactly two children
C. All the leaves are at the same level
D. Each node has exactly one or two children
Solution: A full binary tree is a tree in which each node has exactly 0 or 2 children.
Q: What is a complete binary tree?
A. Each node has exactly zero or two children
B. A binary tree, which is completely filled, with the possible exception of the bottom level, which is filled from right to left
C. A binary tree, which is completely filled, with the possible exception of the bottom level, which is filled from left to right
D. A tree In which all nodes have degree 2
Solution: A binary tree, which is completely filled, with the possible exception of the bottom level, which is filled from left to right is called complete binary tree. A Tree in which each node has exactly zero or two children is called full binary tree. A Tree in which the degree of each node is 2 except leaf nodes is called perfect binary tree.
Q: What is the average case time complexity for finding the height of the binary tree?
A. h = O(loglogn)
B. h = O(nlogn)
C. h = O(n)
D. h = O(log n)
Solution: The nodes are either a part of left sub tree or the right sub tree, so we don’t have to traverse all the nodes, this means the complexity is lesser than n, in the average case, assuming the nodes are spread evenly, the time complexity becomes O(logn).
Q: Which of the following is not an advantage of trees?
A. Hierarchical structure
B. Faster search
C. Router algorithms
D. Undo/Redo operations in a notepad
Solution: Undo/Redo operations in a notepad is an application of stack. Hierarchical structure, Faster search, Router algorithms are advantages of trees.
Q: In a full binary tree if number of internal nodes is I, then number of leaves L are?
A. L = 2*I
B. L = I + 1
C. L = I – 1
D. L = 2*I – 1
Solution: Number of Leaf nodes in full binary tree is equal to 1 + Number of Internal Nodes i.e L = I + 1
Q: In a full binary tree if number of internal nodes is I, then number of nodes N are?
A. N = 2*I
B. N = I + 1
C. N = I – 1
D. N = 2*I + 1
Solution: Relation between number of internal nodes(I) and nodes(N) is N = 2*I+1.
Q: In a full binary tree if there are L leaves, then total number of nodes N are?
A. N = 2*L
B. N = L + 1
C. N = L – 1
D. N = 2*L – 1
Solution: The relation between number of nodes(N) and leaves(L) is N=2*L-1.
Q: Which of the following is incorrect with respect to binary trees?
A. Let T be a binary tree. For every k ≥ 0, there are no more than 2k nodes in level k
B. Let T be a binary tree with λ levels. Then T has no more than 2λ – 1 nodes
C. Let T be a binary tree with N nodes. Then the number of levels is at least ceil(log (N + 1))
D. Let T be a binary tree with N nodes. Then the number of levels is at least floor(log (N + 1))
Solution:  In a binary tree, there are atmost 2k nodes in level k and 2k-1 total number of nodes. Number of levels is at least ceil(log(N+1)).

You Have Score    /10